﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace FUControls.Lists
{
    public partial class ConditionList : UserControl
    {
        string[] fields = new string[] { "Project1", "Project2", "Project3", "Project4" };

        public ConditionList()
        {
            InitializeComponent();

            DG_Condition.ItemsSource = new string[] { "1", "2", "3" };

        }

        private void Cbo_AndOr_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var cbo_AndOr = sender as ComboBox;
            var container = cbo_AndOr.Parent as Grid;
            var dataCell = container.Parent as DataGridCell;

            dataCell.DataContext = cbo_AndOr.SelectedItem;
        }

        private void DG_Condition_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            if (e.Row.GetIndex() == 0)
            {
                var firstContent = DG_Condition.Columns[0].GetCellContent(e.Row);
                var firstDataCell = firstContent.Parent as DataGridCell;

                firstDataCell.IsEnabled = false;
                firstContent.Opacity = 0;
            }
        }

        private void Cbo_Field_Loaded(object sender, RoutedEventArgs e)
        {
            var cbo_Field = sender as ComboBox;
            cbo_Field.ItemsSource = fields;

            var container = cbo_Field.Parent as Grid;
            var dataCell = container.Parent as DataGridCell;
            dataCell.DataContext = cbo_Field;
        }
    }
}
